<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义属性值</title>
</head>

<body>
    <div id="demo" index="1" class="nav"></div>
    <script>
        // 1．获取元素的属性值
        var div = document.querySelector('div'); 
        // (1)element.属性
        console.log(div.id);
        //(2)element.getAttribute( '属性') get得到获取 attribute属性的意思我们程序员自己添加的属性我们称为自定义属性
        console.log(div.getAttribute('id'));
        console.log(div.getAttribute('index'));
        //2.设置自定义属性值element.setAttribute('','')
        div.setAttribute('index','2');//前为属性，后为修改的属性值
        console.log(div.getAttribute('index'));
        div.setAttribute('class','box');
        //3.移除属性removeAttribute
        div.removeAttribute('index');

    </script>
</body>

</html>